package com.ourcraft.informationcollectionsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ourcraft.informationcollectionsystem.entity.DTO.UserDetailInfo;
import com.ourcraft.informationcollectionsystem.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 查询主表为User的数据
 * @author Z0136
 * @since 2023-10-24
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 查询所有企业用户的详细信息
     * @return 所有企业用户的详细信息
     */
    @Select("SELECT u.user_id as userAccount, u.user_status as userStatus, u.role_id as userRole, " +
            "c.company_inst_code as companyInstCode, c.company_chinese_name as userName, " +
            "c.company_record_status as companyRecordStatus, c.company_city as userCity " +
            "FROM User u " +
            "LEFT JOIN Company c ON u.user_id = c.user_id " +
            "WHERE u.role_id = 3")
    @Results({
            @Result(column = "userAccount", property = "userAccount"),
            @Result(column = "userStatus", property = "userStatus"),
            @Result(column = "userRole", property = "userRole"),
            @Result(column = "companyInstCode", property = "companyInstCode"),
            @Result(column = "userName", property = "userName"),
            @Result(column = "companyRecordStatus", property = "companyRecordStatus"),
            @Result(column = "userCity", property = "userCity")
    })
    List<UserDetailInfo> selectUserCompanyInfo();

    /**
     * 查询所有市用户的详细信息
     * @return 所有市用户的详细信息
     */
    @Select("SELECT u.user_id as userAccount, u.role_id as userRole, u.user_status as userStatus, " +
            "c.city_name as userName " +
            "FROM User u " +
            "LEFT JOIN City c ON u.user_id = c.user_id " +
            "WHERE u.role_id = 2")
    @Results({
            @Result(column = "userAccount", property = "userAccount"),
            @Result(column = "userStatus", property = "userStatus"),
            @Result(column = "userRole", property = "userRole"),
            @Result(column = "userName", property = "userName"),
            @Result(column = "userName", property = "userCity")
    })
    List<UserDetailInfo> selectUserCityInfo();

    /**
     * 查询所有省用户的详细信息
     * @return 所有省用户的详细信息
     */
    @Select("SELECT user_id as userAccount, role_id as userRole, user_status as userStatus " +
            "FROM User " +
            "WHERE role_id = 1 and user_id > 0")
    @Results({
            @Result(column = "userAccount", property = "userAccount"),
            @Result(column = "userStatus", property = "userStatus"),
            @Result(column = "userRole", property = "userRole")
    })
    List<UserDetailInfo> selectUserProvinceInfo();
}
